/*
 *说明：用户角色表 首页脚本
 *
 *@author liuxun 2012-03-06
*/


var opeForm;
var grid;

$(function(){
	opeForm = $('#opeForm');

	grid=$('#listTable').datagrid({
		frozenColumns:[[
            {title:'选择',field:'ck',checkbox:true}
		]],
		columns:[[

            {title:'统一登录名',field:'login_name',align:'center',width:80},

            {title:'用户姓名',field:'usr_name',align:'center',width:80},

            {title:'所属机构',field:'org_name',align:'center',width:150},

            {title:'用户类型',field:'usr_type_decode',align:'center',width:80},

            {title:'负责人',field:'is_leader',align:'center',width:60, 
            	formatter:function(value,rec){
           	       return value == '1' ? "<font color='green'>√</font>" : "";
  			    }
             },

            {title:'操作员',field:'is_operator',align:'center',width:60, 
            	formatter:function(value,rec){
          	       return value == '1' ? "<font color='green'>√</font>" : "";
 			    }
            },

            {title:'用户状态',field:'usr_status_decode',align:'center',width:60},

//            {title:'生效时间',field:'effect_time',align:'center',width:80},
//
//            {title:'失效时间',field:'expire_time',align:'center',width:80},

			{title:'操作',field:'operation',align:'center',width:100,
	        	formatter:function(value,rec){
	        		//var s = '<a style="cursor:pointer; color:blue" onclick=\'showInfo("' + rec.key + '")\'>查看明细</a>';
         			var s = '<a style="cursor:pointer; color:blue" onclick=\'showSelectRole("' + rec.key + '")\'>角色授权</a>';
	        	    return s;
		   		}
		    }
        ]],
		pagination:true,
		singleSelect: false
	});

	queryOperation();

	$('#queryBtn').click(queryOperation);
	$('#clearBtn').click(clearOperation);
	$('#reloadBtn').click(refreshWin);
});

//翻页时自动调用此函数
function onLoadPrev(msg){
	var queryParams=grid.datagrid('options').queryParams;
	queryParams['firstQuery']=false;
}

//查询操作
function queryOperation(){
	var params = opeForm.serializeObject();
	grid.datagrid("options").pageNumber = 1;
	grid.datagrid({
		url: 'A_USR!queryList.do',
		queryParams: jQuery.extend({}, params, {'firstQuery': true})
	});
}

//清空操作（重置）
function clearOperation() {
	opeForm.resetForm();
}

//选择机构
function select_a_org() {
	var action = "A_ORG!showTree.do";
	var row = showModalWin(action);
	
	if (row) {
		$('#org_sequence').val(row.attributes.org_sequence);
		$('#org_name').val(row.attributes.org_name);
	}
	
}
//查看明细
function showInfo(key) {
	var url = 'R_USR_ROLE!showInfo.do?model.key=' + key;
	openWin(url,'pop'); 
}

//选择角色信息
function showSelectRole(key) {
	var url = 'R_USR_ROLE!showSelectRole.do?model.usr_id=' + key;
	openWin(url,'pop'); 
}
